{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 第四次练习"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "+ 请务必交到exer4文件夹下，谢绝交到master下\n",
    "+ 请不要改动任何文件，拜托\n",
    "+ 请在10月30日前提交。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "请写一下姓名和学号：\n",
    "+ 姓名  白爽  \n",
    "+ 学号  0165197"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目一\n",
    "一般的歌，分为主歌和副歌部分。副歌有重复，对比两大功能。这就是A－B的基本曲式形式结构。  \n",
    "请找一首你的主打歌，把歌词打印出来，重复的副歌部分，请写一个函数，调用函数打印出来。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "让我留在你身边——陈奕迅\n",
      "我从来不说话\n",
      "因为我害怕\n",
      "没有人回答\n",
      "我从来不挣扎\n",
      "因为我知道\n",
      "这世界太大\n",
      "太多时间浪费 太多事要面对\n",
      "太多已无所谓 太多难辨真伪\n",
      "太多纷扰是非 在你身边是谁\n",
      "最渺小的我\n",
      "有大大的梦\n",
      "时间向前走\n",
      "一定只有路口没有尽头\n",
      "纷纷扰扰这个世界 所有的了解\n",
      "只要 让我留在你身边\n",
      "最渺小的我\n",
      "有大大的梦\n",
      "时间向前走\n",
      "一定只有路口没有尽头\n",
      "纷纷扰扰这个世界 所有的了解\n",
      "只要 让我留在你身边\n"
     ]
    }
   ],
   "source": [
    "print(\"让我留在你身边——陈奕迅\")\n",
    "def f():\n",
    "    print(\"最渺小的我\\n有大大的梦\\n时间向前走\\n一定只有路口没有尽头\\n纷纷扰扰这个世界 所有的了解\\n只要 让我留在你身边\")    \n",
    "print(\"我从来不说话\\n因为我害怕\\n没有人回答\\n我从来不挣扎\\n因为我知道\\n这世界太大\\n太多时间浪费 太多事要面对\\n太多已无所谓 太多难辨真伪\\n太多纷扰是非 在你身边是谁\")\n",
    "f()\n",
    "f()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目二\n",
    "请写一个函数，能够计算均值、样本方差和n(自己写公式哦)。\n",
    "每次输入十个以上的数字，能够输出上述三个统计量。\n",
    "至少调用两次。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "n=11\n",
      "均值为6.0\n",
      "方差为11.0\n",
      "n=12\n",
      "均值为17.5\n",
      "方差为13.0\n"
     ]
    }
   ],
   "source": [
    "def function(*numbers):\n",
    "    count=0\n",
    "    sum=0\n",
    "    for number in numbers:\n",
    "        count+=1\n",
    "        sum+=number\n",
    "    average=sum/count\n",
    "    print(\"n=%s\"%count)\n",
    "    print(\"均值为%s\"%average)\n",
    "    sumsquare=0\n",
    "    for number in numbers:\n",
    "        sumsquare+=(number-average)**2\n",
    "        s=sumsquare/(count-1)\n",
    "    print(\"方差为%s\"%s)\n",
    "function(1,2,3,4,5,6,7,8,9,10,11)\n",
    "function(12,13,14,15,16,17,18,19,20,21,22,23)\n",
    "        \n",
    "        \n",
    "    \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目三\n",
    "刚才那个函数，默认的是输出均值、样本方差和n，请在后面添加一个关键词参数，让这个函数可以选择输出样本标准差或方差。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "n=10\n",
      "均值为6.5\n",
      "标准差输入0，方差输入1\n",
      "0\n",
      "标准差为3.0276503540974917\n",
      "n=11\n",
      "均值为18.0\n",
      "标准差输入0，方差输入1\n",
      "1\n",
      "方差为11.0\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "def function(op=None,*numbers):\n",
    "    count=0\n",
    "    sum=0\n",
    "    for number in numbers:\n",
    "        count+=1\n",
    "        sum+=number\n",
    "    average=sum/count\n",
    "    print(\"n=%s\"%count)\n",
    "    print(\"均值为%s\"%average)\n",
    "    sumsquare=0\n",
    "    for number in numbers:\n",
    "        sumsquare+=(number-average)**2\n",
    "        s=sumsquare/(count-1)\n",
    "        stdvar=math.sqrt(s)\n",
    "    print(\"标准差输入0，方差输入1\")\n",
    "    op=int(input())\n",
    "    if op==1:\n",
    "            print(\"方差为%s\"%s)\n",
    "    if op==0:\n",
    "            \n",
    "            print(\"标准差为%s\"%stdvar)    \n",
    "function(1,2,3,4,5,6,7,8,9,10,11)\n",
    "function(12,13,14,15,16,17,18,19,20,21,22,23)\n",
    "        \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目四\n",
    "刚才那个函数，请再增加三个关键词参数，让这个参数可以选择输出均值的标准误、最大值、最小值或不输出这三个统计量。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "n=7\n",
      "均值为8.0\n",
      "标准差输入0，方差输入1\n",
      "0\n",
      "标准差为2.160246899469287\n",
      "标准误输入1，不输出输入0\n",
      "1\n",
      "标准误为0.816496580927726\n",
      "最大值输入1，不输出输入0\n",
      "1\n",
      "最大值为11\n",
      "最小值输入1，不输出输入0\n",
      "1\n",
      "最小值为5\n",
      "n=8\n",
      "均值为19.5\n",
      "标准差输入0，方差输入1\n",
      "1\n",
      "方差为6.0\n",
      "标准误输入1，不输出输入0\n",
      "0\n",
      "最大值输入1，不输出输入0\n",
      "0\n",
      "最小值输入1，不输出输入0\n",
      "0\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "def function(op1=None,op2=None,op3=None,op4=None,*numbers):\n",
    "    count=0\n",
    "    sum=0\n",
    "    for number in numbers:\n",
    "        count+=1\n",
    "        sum+=number\n",
    "    average=sum/count\n",
    "    print(\"n=%s\"%count)\n",
    "    print(\"均值为%s\"%average)\n",
    "    sumsquare=0\n",
    "    for number in numbers:\n",
    "        sumsquare+=(number-average)**2\n",
    "        s=sumsquare/(count-1)\n",
    "        stdvar=math.sqrt(s)\n",
    "        MSE=stdvar/math.sqrt(count)\n",
    "        MAX=max(numbers)\n",
    "        MIN=min(numbers)\n",
    "    print(\"标准差输入0，方差输入1\")\n",
    "    op1=int(input())\n",
    "    if op1==1:\n",
    "            print(\"方差为%s\"%s)\n",
    "    if op1==0:\n",
    "            \n",
    "            print(\"标准差为%s\"%stdvar) \n",
    "    print(\"标准误输入1，不输出输入0\")\n",
    "    op2=int(input())\n",
    "    if op2==1:\n",
    "            print(\"标准误为%s\"%MSE)\n",
    "    print(\"最大值输入1，不输出输入0\")\n",
    "    op3=int(input())\n",
    "    if op3==1:\n",
    "            print(\"最大值为%s\"%MAX)\n",
    "    print(\"最小值输入1，不输出输入0\")\n",
    "    op4=int(input())\n",
    "    if op4==1:\n",
    "            print(\"最小值为%s\"%MIN)            \n",
    "            \n",
    "function(1,2,3,4,5,6,7,8,9,10,11)\n",
    "function(12,13,14,15,16,17,18,19,20,21,22,23)\n",
    "        "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
